/**
 * Copyright (c) 2014-2015, Suredy technology Co., Ltd. All rights reserved.
 * @author ZhangMaoren 
 * @since 2015年4月14日
 * @version 0.1
 */
package com.suredy.config.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;

import com.suredy.config.model.FileTypeConfig;
import com.suredy.core.service.BaseSrvWithEntity;


/**
 * @author ZhangMaoren
 *
 */
@Service("FileTypeConfigSrv")
public class FileTypeConfigSrv extends BaseSrvWithEntity<FileTypeConfig>{
	@Override
	public DetachedCriteria getDc(FileTypeConfig t) {
		DetachedCriteria dc = super.getDc(t);
		if (t == null) {
			return dc;
		}
		if (!StringUtils.isBlank(t.getId())) {
			dc.add(Restrictions.eq("id", t.getId()));
		}
		
		if (!StringUtils.isBlank(t.getFlowUN())) {
			dc.add(Restrictions.eq("flowUN", t.getFlowUN()));
		}
		
		if (!StringUtils.isBlank(t.getAppId())) {
			dc.add(Restrictions.eq("appId", t.getAppId()));
		}

		return dc;
	}
	
	public List<FileTypeConfig> getAll() {
		return this.readByEntity(null);
	}
	
	public FileTypeConfig get(String id) {
		return super.get(id);
	}
	
	public FileTypeConfig getFileTypeByCode(String fileTypeCode) {
		if (StringUtils.isBlank(fileTypeCode)) {
			return null;
		}
		FileTypeConfig search = new FileTypeConfig();
		search.setFlowUN(fileTypeCode);
		FileTypeConfig r = this.readSingleByEntity(search);
		
		return r;
	}
	
	
	public List<FileTypeConfig> getFileTypeByAppId(String appId) {
		List<FileTypeConfig> ret;
		if (StringUtils.isBlank(appId)) {
			ret = this.readByEntity(null);
		} else {
			FileTypeConfig search = new FileTypeConfig();
			search.setAppId(appId);
			ret = this.readByEntity(search);
		}
		return ret; 
	}

	public void add(FileTypeConfig config) {
		this.saveOrUpdate(config);
	}
	
	public void update(FileTypeConfig config) {
		this.update(config);
	}
	
	public void remove(FileTypeConfig config) {
		this.delete(config);
	}
}
